/**
 * $RCSfile: TestMediaManager.java,v $
 * $Revision: 1.3 $
 * $Date: 25/12/2006
 * <p/>
 * Copyright 2003-2006 Jive Software.
 * <p/>
 * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p/>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p/>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jivesoftware.smackx.jingle.mediaimpl.testxing;

import org.jivesoftware.smackx.jingle.media.JingleMediaManager;
import org.jivesoftware.smackx.jingle.media.JingleMediaSession;
import org.jivesoftware.smackx.jingle.media.PayloadType;
import org.jivesoftware.smackx.jingle.mediaimpl.jmf.JmfMediaManager;
import org.jivesoftware.smackx.jingle.nat.JingleTransportManager;
import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
import org.jivesoftware.smackx.jingle.JingleSession;
import org.jivesoftware.smackx.jingle.SmackLogger;

import java.util.*;

/**
 * Implements a MediaManager for test purposes.
 * 
 * @author Thiago Camargo
 */

public class TestXingMediaManager extends JingleMediaManager {

	private static final SmackLogger LOGGER = SmackLogger
			.getLogger(TestXingMediaManager.class);

	public static final String MEDIA_NAME = "TestXingMedia";

	private List<PayloadType> payloads = new ArrayList<PayloadType>();

	private PayloadType preferredPayloadType = null;

	public TestXingMediaManager(JingleTransportManager transportManager) {
		super(transportManager);
		setupPayloads();
	}

	/**
	 * Setup API supported Payloads
	 */
	private void setupPayloads() {
		payloads.add(new PayloadType.Audio(0, "PCMU", 8000));
	}

	/**
	 * Return all supported Payloads for this Manager.
	 * 
	 * @return The Payload List
	 */
	public List<PayloadType> getPayloads() {
		return payloads;
	}

	public void setPayloads(List<PayloadType> payloads) {
		this.payloads.addAll(payloads);
	}

	/**
	 * Returns a new JingleMediaSession
	 * 
	 * @param payloadType
	 *            payloadType
	 * @param remote
	 *            remote Candidate
	 * @param local
	 *            local Candidate
	 * @return JingleMediaSession JingleMediaSession
	 */
	public JingleMediaSession createMediaSession(PayloadType payloadType,
			final TransportCandidate remote, final TransportCandidate local,
			final JingleSession jingleSession) {
		TestXingMediaSession session = null;

		session = new TestXingMediaSession(payloadType, remote, local, "",
				jingleSession);

		return session;
	}

	public PayloadType getPreferredPayloadType() {
		if (preferredPayloadType != null)
			return preferredPayloadType;
		return super.getPreferredPayloadType();
	}

	public void setPreferredPayloadType(PayloadType preferredPayloadType) {
		this.preferredPayloadType = preferredPayloadType;
	}

	public String getName() {
		return MEDIA_NAME;
	}
}
